﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Teamplate.Master" AutoEventWireup="true" CodeBehind="TimKiem.aspx.cs" Inherits="WebNhaXuatBan.TimKiem" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<a style="margin-left:30px;" href="default.aspx"><img src="Images/Folder-Home-Folder-icon.png" alt="Group EM09" /></a>
    <a style="margin-left:30px;"  href="DauThauSach.aspx"><img src="Images/TimKiemSach.png" alt="Group EM09" /></a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
 <div style="width:980px; margin-left:auto; margin-right:auto; border:1px solid #bad9eb;">
<div style="width:980px;height:30px; background-image:url(../Images/ThanhTieuDe.png);"></div>
<div style="height:20px;margin-top:5px;margin-left:5px;margin-bottom:10px;">
<div id="BODY">
<%
    string tam = Request.QueryString["TieuChi"];
    int tieuChi = int.Parse(tam);
    string chuoiTimKiem = Request.QueryString["ChuoiTimKiem"];
    int soBatDauTrang = int.Parse(Request.QueryString["SoBatDau"]);
   BUS.SachBUS sach=new BUS.SachBUS();
   ArrayList dssach = new ArrayList();
    if (tieuChi == 0)
    {
        dssach = sach.TimKiemSachTheoTenSach(chuoiTimKiem);
    }
    else
    {
        if (tieuChi == 1)
        {
            dssach = sach.TimKiemSachTheoTenTacGia(chuoiTimKiem);
        }
        else
        {
            if (tieuChi == 2)
            {
                dssach = sach.TimKiemSachTheoTenLoaiSach(chuoiTimKiem);
            }
        }  
    }
   int soBatDau = soBatDauTrang;
   int count = dssach.Count;
   int sotrang = 0;
   if (dssach.Count > 5)
   {
       count = 5;
       sotrang = dssach.Count / 5;
       if (dssach.Count % 5 > 0)
       {
           if (soBatDau == dssach.Count / 5)
           {
               count = dssach.Count % 5;
           }
           sotrang++;
       }
   }
   if (sotrang != 0 && sotrang != 1)
   { 
    %>
     <a style=" margin-left:2px; color:#4ba2d5" href="TimKiem.aspx?TieuChi=<%=tieuChi  %>&ChuoiTimKiem=<%=chuoiTimKiem %>&SoBatDau=0">Trang Đầu</a>
     <%int sob = soBatDau / 10;
                sob = sob * 10;
                int soc = sob + 10;
                if (soc > sotrang)
                {
                    soc = sotrang;
                }
                if (sob != 0)
                {
        %>
        <a style=" margin-left:2px; color:#4ba2d5;" href="TimKiem.aspx?TieuChi=<%=tieuChi  %>&ChuoiTimKiem=<%=chuoiTimKiem %>&SoBatDau=<%=sob-1 %>"><< Trước</a>
        <%}
            for (int i = sob; i < soc; i++)
            {
                if (i == soBatDau)
                {
                    %><span><%=i %></span>
                    <%
                }
                else
                {%>
                    <a style=" margin-left:2px; color:#4ba2d5;" href="TimKiem.aspx?TieuChi=<%=tieuChi  %>&ChuoiTimKiem=<%=chuoiTimKiem %>&SoBatDau=<%=i %>><%=i %></a>
                        <%
                }
            }
            if (soc < sotrang)
            {
                %>
                <a style=" margin-left:2px; color:#4ba2d5;" href="TimKiem.aspx?TieuChi=<%=tieuChi  %>&ChuoiTimKiem=<%=chuoiTimKiem %>&SoBatDau=<%=soc %>"></a><%
            }
            if (sotrang != 0 && sotrang != 1)
            {
                %>
                <a style=" margin-left:2px; color:#4ba2d5;" href="TimKiem.aspx?TieuChi=<%=tieuChi  %>&ChuoiTimKiem=<%=chuoiTimKiem %>&SoBatDau=<%=sotrang-1 %>">Trang Cuối</a><%
            }
                     %>
        <%} %>
        <br /><span style="margin-left:2px; margin-top:5px;">Hiển Thị:<%=" "+count %>/<%=dssach.Count+" kết quả" %></span>
    <%
   for (int j = soBatDau*5; j < soBatDau*5+count; j++)
   {%>
   <br />
   <hr />
   <div style="height:300px;margin-top:5px;margin-left:5px;width:100%;">
   <div style="height:300px;float:left;width:300px;">
   <a href="#"><img src="<%=((DTO.SachDTO)dssach[j]).FileHinh %>" alt="<%=((DTO.SachDTO)dssach[j]).FileHinh %>") /></a>
   </div>
   <div style="height:300px;float:left;width:600px;">
   <span style="color:#366276; font-size:30px;"><%= ((DTO.SachDTO)dssach[j]).TenSach%></span>
   <br />
   Tác Giả:<%=" "+((DTO.SachDTO)dssach[j]).TacGia%>
   <br />
   <span style="color:red;">Giá Bán:<%= " " + ((DTO.SachDTO)dssach[j]).GiaBan%>$</span>
   <br />
   <span style="color:red;"><%if (((DTO.SachDTO)dssach[j]).SoLuongTon != 0)
                              { %> Còn Hàng <%}
                              else
                              {%>Hết Hàng<%} %></span>
   <br />
   <%if (Session["TaiKhoan"] != null)
     { %><a href="DatMua.aspx?MaSach=<%=((DTO.SachDTO)dssach[j]).MaSach %>"><%}
     else
     { %><a href="DangKy.aspx"><%} %><img src="Images/buttonmuahang1.jpg" /></a>
   </div>
   </div>
   <%} %>
   <div style="width:980px;height:10px;"></div>
</div>
</div>
</asp:Content>
